<?php defined( '_MAXSITE' ) or die( 'Restricted access' ); ?>
<TABLE WIDTH="660" BORDER="0" ALIGN="center" CELLPADDING="0" CELLSPACING="0">
  <TR>
            <TD width="10" vAlign=top></TD>
          <TD width="640" vAlign=top colspan="2"><BR>

      &nbsp;&nbsp;<IMG SRC="images/menu/textmenu_member.gif" BORDER="0">
<?php
$forget = $_POST['forget'];
$emails = $_POST['emails'];
if(!empty($forget) && !empty($emails)) {
$emails = $_POST['emails'];
$db->connectdb(DB_NAME,DB_USERNAME,DB_PASSWORD);
$sql = sprintf("SELECT id, email, name, user FROM ".TB_MEMBER." WHERE email='%s' LIMIT 1", 
        mysql_real_escape_string($emails)
        );
$result = mysql_query($sql);
$numrow = mysql_num_rows($result);
$dbarr = mysql_fetch_object($result);

if($numrow===0 OR $dbarr===FALSE)
{
    echo "<center><font size='3' face='MS Sans Serif'><b>ไม่มีอีเมลนี้อยู่ในระบบจ้า ;)</b></font></center>" ;
}
else if($numrow>0 && $dbarr->email)
{
    $email = $dbarr->email;
    $name = $dbarr->name;
    $user = $dbarr->user;
    $randval = substr(md5(mt_rand()), 0, 12);
    
    $sql = "UPDATE ".TB_MEMBER." SET changepass='".$randval."' WHERE id=".$dbarr->id." LIMIT 1;";
    $result = mysql_query($sql);
    
    resetpassword($email, $name, $user, $randval);
    //echo "<meta http-equiv=refresh content='3;URL=index.php'>" ;
}

} else {
?>
	<FORM ACTION="?name=member&file=forget_pwd" METHOD="post">
              
        <TABLE WIDTH="640" BORDER="0" ALIGN="center" CELLPADDING="3" CELLSPACING="1">
		            <TR VALIGN="top"> 
                  <TD COLSPAN="2" align="center"> 
                    
                     
                      
                       <DIV ALIGN="center"><P><FONT COLOR="#000000" SIZE="2"><STRONG></STRONG></FONT></P>
                      <P><FONT COLOR="#000000" SIZE="2"><STRONG><?=_MEMBER_MOD_RESET_PASS_ADD;?></STRONG></FONT></P>
                    </DIV></TD>
      </TR>
	
      <TR> 
                  
            <TD align="right" BGCOLOR="#FFFFFF" ><FONT SIZE="2"><STRONG>email</STRONG></FONT></TD>
        <TD BGCOLOR="#FFFFFF"><INPUT NAME="emails" TYPE="text" ID="emails" size="20" ></TD>
      </TR>
	  <TR> 
                  
            <TD align="center" BGCOLOR="#FFFFFF" >&nbsp;</TD>
				            <TD BGCOLOR="#FFFFFF"> 
            <INPUT TYPE="submit" NAME="Submit" VALUE="send password">
            <INPUT NAME="forget" TYPE="hidden" ID="forget" VALUE="forget">
            &nbsp; </TD>
      </TR>
	        <TR> 
                  <TD COLSPAN="2" BGCOLOR="#FFFFFF"><DIV ALIGN="center">
                    <P><STRONG><FONT COLOR="#FF0000" SIZE="1" FACE="MS Sans Serif, Tahoma, sans-serif"><?=_MEMBER_MOD_RESET_PASS_SEND;?> </FONT></STRONG></P>
                  </DIV></TD>
      </TR>
	  
    </TABLE>
	
</FORM>

<?
	}
?>
	</TD>
  </TR>
</TABLE>